package ag.webpage.snapshot;

import browser.Chorme;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.WebDriver;
import util.FileCreator;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class SnapShot {
    public File webPage;
    public BufferedImage bufferedImage;

    public void shot(WebDriver tab) {
        webPage = Chorme.snapshot(tab, false);
        try {
            bufferedImage = ImageIO.read(webPage);
        } catch (IOException e) {
            e.printStackTrace();
        }
        File f = FileCreator.checkExist("屏幕截图/index.png");
        try {
            //ImageIO.write(bufferedImage, "png", f);
            FileUtils.copyFile(webPage, new File("屏幕截图", "index.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
     /*  for (int i = 0; i < Position.positionsTime.length; i++) {
            BufferedImage elementSnapShot = AgImgUtil.getPositionBufferedImageNoSelect(bufferedImage, Position.positionsTime[i]);
            elementSnapShot = ImgUtil.selectGRB(elementSnapShot, 130);
            ImgUtil.savePic(elementSnapShot, "屏幕截图/ceshi" + i + ".jpg");
            File f = FileCreator.checkExist("屏幕截图/ceshi" + i + ".jpg");
            String result = tesseract.Test.getResult(f);
            System.out.println(result);
        }*/
    }
}
